#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib
import urllib2
import cookielib
import re

username = 'torri1'
password = '9021'

cj = cookielib.CookieJar()
cj.clear()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
login_data = urllib.urlencode({'j_username' : username, 'j_password' : password})
opener.open('https://www.positronrt.com.br/rastreador/login.htm', login_data)
resp = opener.open('http://www.positronrt.com.br/rastreador/odometer.xhtml').read()
result = re.findall("value=\"([0-9]{5})\">([0-9A-Z]{7})", resp)
print resp
#if not result:
#	print "Erro ao atualizar hodômetros.\nSaindo."
#	exit

#for entry in result:
#	url = 'http://www.positronrt.com.br/rastreador/odometer.xhtml?idvehicle=%s' % (entry[0])
#	print url
	#foo = opener.open(url).read()
#	print foo
#	af = re.findall("([0-9.,]+)\ km", foo)
#	print af
